package com.hogan.hoganproject.utils;

import android.text.TextUtils;

import com.github.stuxuhai.jpinyin.PinyinFormat;
import com.github.stuxuhai.jpinyin.PinyinHelper;

/**
 * Author: chenhu
 * Time: 2020/9/17 16:49
 * Description do somethings
 */
public class StringUtils {
    public static String getHeadViewFirstName(String name) {
        String curName = "";
        if (TextUtils.isEmpty(name)) {
            return curName;
        }
        int index = name.length() - 1;
        for (int i = index; i >= 0; i--) {
            char firstStr = name.charAt(i);
            if (isPinyin(String.valueOf(firstStr))) {
                curName = String.valueOf(firstStr);
                return curName;
            }
        }
        return curName;
    }


    public static boolean isPinyin(String src) {
        String res = src;
        try {
            res = PinyinHelper.convertToPinyinString(src, "", PinyinFormat.WITHOUT_TONE).toUpperCase();
        } catch (Exception e) {
        }
        if (res.charAt(0) >= 'A' && res.charAt(0) <= 'Z') {
            return true;
        } else {
            return false;
        }
    }
}
